import config from "./config";

// 封装请求
export default (url, data = {}, method = 'GET') => {
  return new Promise((resolve, reject) => {
    let cookie = wx.getStorageSync('cookies') ? wx.getStorageSync('cookies') : '';
    wx.request({
      url: config.host + url,
      data: data,
      method: method,
      header: {cookie},
      success: (res)=>{
        if (data.isLogin){
          let itemCookie = res.cookies.find(item=> /^MUSIC_U/.test(item) === true );
          wx.setStorage({
            key: 'cookies',
            data: itemCookie,
          })
        }
        resolve(res.data)
      },
      fail: (err)=>{
        reject(err)
      },
    })
  })
}